<template>
	<view>
		<view class="menu-list">
			<view class="menu-item" @tap="changeImg()">
				<text>修改头像</text>
				<i class="icon">&#xe60f;</i>
			</view>
			<view class="menu-item" @tap="updatepwd()">
				<text>修改密码</text>
				<i class="icon">&#xe60f;</i>
			</view>
		</view>
		<button class='out-login' @tap="outLogin()">退出登录</button>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				
			}
		},
		methods:{
			updatepwd(){
				uni.navigateTo({
					url:'update-pwd'
				})
			},
			outLogin(){
				this.ajax('user/tuichu',{
					data:{},
					success:(res) => {
						res = res.data;
						this.toasts(res.info);
						if(res.status) {
							uni.reLaunch({
								url:"../login/index"
							})
						}
					}
				});
			},
			changeImg(){
				uni.chooseImage({
					count : 1,
					success:(res) => {
						var file = res.tempFiles[0].path;
						var reader = new plus.io.FileReader();  
						reader.onloadend = (e) => {  
							var img = e.target.result;
							this.ajax('user/editpic',{
								data:{
									pic :img 
								},
								success:(res) => {
									res = res.data;
									this.toasts(res.info);
									if(res.status) {
										setTimeout(()=>{
											uni.switchTab({
												url:"../user/index"
											})
										},1000)
									}
								}
							})
							  //e.target.result;
						};  
						reader.readAsDataURL(file);
					}
				})
			}
		}
	}
</script>

<style>
	.menu-list{width: calc(100% - 40upx);margin:auto;}
	.menu-item{height:120upx;background: #FFFFFF;margin-top: 20upx;line-height: 120upx;padding:0 20upx;}
	.menu-item .icon{float:right;color:#999}
	.out-login{border:none;width: 90%;margin:auto;color:#FFFFFF;background: #F56C6C;margin-top: 40upx;}
</style>
